import {
  PersonModel
} from '../../models/personal.js'
let personModel = new PersonModel()
import {
  AuthModel
} from '../../models/authData.js'
let authModel = new AuthModel()
import {
  LoginModel
} from '../../models/hdd/login.js'
let loginModel = new LoginModel()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    personalData: '',
    receivingCount: 0,
    closedCount: 0,
    skillGradeText: '',
    authBtnTitle: '立即认证',
    FGatheringCode: '',
    authenticationStatus: '1',
  },

  pageLifetimes: {
    show() {
      wx.showLoading({
        mask: true
      })
      const personal = personModel.getPersonalData()
      const orderInfo = personModel.getOrderData()
      const auth = authModel.getSelfAuthData()
      Promise.all([personal, orderInfo, auth])
        .then(res => {
          let ifAuthentication
          let status
          if (res[2].data.data.resumeData.authenticationInfoList[0]) {
            if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'New' || res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Back') {
              ifAuthentication = '立即认证'
            } else {
              if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Auditing') {
                ifAuthentication = '更新认证'
                status = '2'
              }
              if (res[2].data.data.resumeData.authenticationInfoList[0].FAuthenticationStatus === 'Audited') {
                status = '3'
                ifAuthentication = '更新认证'
              }
            }
          } else {
            status = '1'
            ifAuthentication = '立即认证'
          }
          wx.hideLoading()
          var FSkillGradeText = ''
          var FGatheringCode = ''
          if (res[2].data.data.resumeData.authenticationInfoList[0]) {
            FSkillGradeText = res[2].data.data.resumeData.authenticationInfoList[0].FSkillGradeText
          }

          if (res[2].data.data.resumeData.authenticationInfoList[0]) {
            FGatheringCode = res[2].data.data.resumeData.authenticationInfoList[0].FGatheringCode
          }

          this.setData({
            personalData: res[0].data.data.records ? res[0].data.data.records : '',
            closedCount: res[1].data.data.closedCount ? res[1].data.data.closedCount : 0,
            receivingCount: res[1].data.data.receivingCount ? res[1].data.data.receivingCount : 0,
            skillGradeText: FSkillGradeText ? FSkillGradeText : '',
            FGatheringCode: FGatheringCode,
            authBtnTitle: ifAuthentication ? ifAuthentication : '',
            authenticationStatus: status ? status : '',
          })
        })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    pushToOrderList() {
      wx.navigateTo({
        url: '/pages/orderList/orderList',
      })
    },

    logout() {
      wx.showModal({
        showCancel: true,
        title: '提示',
        content: '确定要注销吗?',
        success(res) {
          if (res.confirm) {
            const logout = loginModel.logout()
            logout.then(res => {
              if (res.data.success) {
                wx.reLaunch({
                  url: '/pages/login/login',
                })
              }
            })
          }
        }
      })
    },

    pushToAuth() {
      wx.navigateTo({
        url: `/pages/auth/auth?FItEmpId=${this.data.personalData.FId}`,
      })
    },

    pushToPersonInfo() {
      wx.navigateTo({
        url: `/pages/personInfo/personInfo?personalData=${JSON.stringify(this.data.personalData)}`
      })
    },

    pushToEditPersonInfo() {
      wx.navigateTo({
        url: `/pages/editPersonInfo/editPersonInfo?fromPage=me&mobile=${this.data.personalData.FMobile}`,
      })
    },
    
    showCode() {
      if (!this.data.FGatheringCode) {
        return
      }
      var url = 'https://www.myhr100.com:4200/Ecp.Picture.view.img?pictureId=' + this.data.FGatheringCode
      var urls = [url]
      wx.previewImage({
        current: url,
        urls: urls,
      })
    }
  }
})